const Omit = require("../template")

function testOmitPerformance() {
  console.log(
    "1. 对象排除性能测试 - 大量属性排除:",
    (() => {
      const largeObject = {}
      for (let i = 0; i < 10000; i++) {
        largeObject[`prop${i}`] = i
      }
      const start = performance.now()
      const result = Omit.omit(largeObject, 'prop0', 'prop1', 'prop2')
      const end = performance.now()
      return (end - start) < 100 && Object.keys(result).length === 9997
    })()
  )

  console.log(
    "2. 对象排除性能测试 - 内存使用:",
    (() => {
      const initialMemory = process.memoryUsage().heapUsed
      const largeObject = {}
      for (let i = 0; i < 10000; i++) {
        largeObject[`prop${i}`] = i
      }
      const result = Omit.omit(largeObject, 'prop0', 'prop1', 'prop2')
      const finalMemory = process.memoryUsage().heapUsed
      const memoryIncrease = finalMemory - initialMemory
      return memoryIncrease < 1024 * 1024 // 内存增长应该小于1MB
    })()
  )

  console.log(
    "3. 对象排除性能测试 - 深度排除:",
    (() => {
      const largeObject = {}
      for (let i = 0; i < 1000; i++) {
        largeObject[`prop${i}`] = { nested: { value: i } }
      }
      const start = performance.now()
      const result = Omit.omitDeep(largeObject, 'prop0.nested.value', 'prop1.nested.value')
      const end = performance.now()
      return (end - start) < 50 && Object.keys(result).length === 998
    })()
  )

  console.log(
    "4. 对象排除性能测试 - 条件排除:",
    (() => {
      const largeObject = {}
      for (let i = 0; i < 10000; i++) {
        largeObject[`prop${i}`] = i
      }
      const start = performance.now()
      const result = Omit.omitBy(largeObject, (value, key) => value > 5000)
      const end = performance.now()
      return (end - start) < 50 && Object.keys(result).length === 5001
    })()
  )

  console.log(
    "5. 对象排除性能测试 - 类型排除:",
    (() => {
      const largeObject = {}
      for (let i = 0; i < 10000; i++) {
        largeObject[`prop${i}`] = i % 2 === 0 ? i : i.toString()
      }
      const start = performance.now()
      const result = Omit.omitByType(largeObject, 'string')
      const end = performance.now()
      return (end - start) < 50 && Object.keys(result).length === 5000
    })()
  )

  console.log(
    "6. 对象排除性能测试 - 正则排除:",
    (() => {
      const largeObject = {}
      for (let i = 0; i < 10000; i++) {
        largeObject[`prop${i}`] = i
      }
      const start = performance.now()
      const result = Omit.omitByPattern(largeObject, /[0-9]/)
      const end = performance.now()
      return (end - start) < 50 && Object.keys(result).length === 0
    })()
  )

  console.log(
    "7. 对象排除性能测试 - 默认值排除:",
    (() => {
      const largeObject = {}
      for (let i = 0; i < 1000; i++) {
        largeObject[`prop${i}`] = i
      }
      const start = performance.now()
      const result = Omit.omitWithDefaults(largeObject, 'prop0', 'prop1', { prop2: 0 })
      const end = performance.now()
      return (end - start) < 50 && Object.keys(result).length === 999
    })()
  )

  console.log(
    "8. 对象排除性能测试 - 转换排除:",
    (() => {
      const largeObject = {}
      for (let i = 0; i < 1000; i++) {
        largeObject[`prop${i}`] = i
      }
      const start = performance.now()
      const result = Omit.omitWithTransform(largeObject, 'prop0', 'prop1', { prop2: x => x * 2 })
      const end = performance.now()
      return (end - start) < 50 && Object.keys(result).length === 999
    })()
  )

  console.log(
    "9. 对象排除性能测试 - 验证排除:",
    (() => {
      const largeObject = {}
      for (let i = 0; i < 10000; i++) {
        largeObject[`prop${i}`] = i
      }
      const start = performance.now()
      const result = Omit.omitWithValidation(largeObject, 'prop0', 'prop1', { min: 0, max: 10000 })
      const end = performance.now()
      return (end - start) < 50 && Object.keys(result).length === 9998
    })()
  )

  console.log(
    "10. 对象排除性能测试 - 重复属性排除:",
    (() => {
      const largeObject = {}
      for (let i = 0; i < 10000; i++) {
        largeObject[`prop${i}`] = 1
      }
      const start = performance.now()
      const result = Omit.omit(largeObject, 'prop0', 'prop1', 'prop2')
      const end = performance.now()
      return (end - start) < 50 && Object.keys(result).length === 9997
    })()
  )

  console.log(
    "11. 对象排除性能测试 - 无重复属性排除:",
    (() => {
      const largeObject = {}
      for (let i = 0; i < 10000; i++) {
        largeObject[`prop${i}`] = i
      }
      const start = performance.now()
      const result = Omit.omit(largeObject, 'prop0', 'prop1', 'prop2')
      const end = performance.now()
      return (end - start) < 50 && Object.keys(result).length === 9997
    })()
  )

  console.log(
    "12. 对象排除性能测试 - 混合类型排除:",
    (() => {
      const largeObject = {}
      for (let i = 0; i < 10000; i++) {
        largeObject[`prop${i}`] = i % 3 === 0 ? i : i % 3 === 1 ? i.toString() : { id: i }
      }
      const start = performance.now()
      const result = Omit.omitByType(largeObject, 'string')
      const end = performance.now()
      return (end - start) < 50 && Object.keys(result).length === 6667
    })()
  )

  console.log(
    "13. 对象排除性能测试 - 嵌套对象排除:",
    (() => {
      const largeObject = {}
      for (let i = 0; i < 1000; i++) {
        largeObject[`prop${i}`] = { id: i, data: { value: i, nested: { deep: i % 10 } } }
      }
      const start = performance.now()
      const result = Omit.omitDeep(largeObject, 'prop0.data.value', 'prop1.data.value')
      const end = performance.now()
      return (end - start) < 50 && Object.keys(result).length === 998
    })()
  )

  console.log(
    "14. 对象排除性能测试 - 并发处理:",
    (() => {
      const largeObject = {}
      for (let i = 0; i < 10000; i++) {
        largeObject[`prop${i}`] = i
      }
      const start = performance.now()
      
      const promises = []
      for (let i = 0; i < 10; i++) {
        promises.push(Promise.resolve().then(() => Omit.omit(largeObject, 'prop0', 'prop1', 'prop2')))
      }
      
      return Promise.all(promises).then(results => {
        const end = performance.now()
        return (end - start) < 200 && results.every(r => Object.keys(r).length === 9997)
      })
    })()
  )

  console.log(
    "15. 对象排除性能测试 - 内存泄漏检测:",
    (() => {
      const initialMemory = process.memoryUsage().heapUsed
      
      for (let i = 0; i < 100; i++) {
        const largeObject = {}
        for (let j = 0; j < 1000; j++) {
          largeObject[`prop${j}`] = j
        }
        const result = Omit.omit(largeObject, 'prop0', 'prop1', 'prop2')
      }
      
      if (global.gc) {
        global.gc()
      }
      
      const finalMemory = process.memoryUsage().heapUsed
      const memoryIncrease = finalMemory - initialMemory
      
      return memoryIncrease < 1024 * 1024 // 内存增长应该小于1MB
    })()
  )
}

testOmitPerformance()
